package utils;

public class Vector {
    public Double x;
    public Double y;

    public Vector(Double x, Double y) {
        this.x = x;
        this.y = y;
    }

    public Vector(Double[] start, Double[] end) {
        this.x = end[0] - start[0];
        this.y = end[1] - start[1];
    }

    /**
     * Dot Operation
     * @param v1 vector1
     * @param v2 vector2
     * @return Dot Result.
     */
    public static Double Dot(Vector v1, Vector v2) {
        return v1.x * v2.x +
                v1.y * v2.y ;
    }

    /**
     * Det Operation
     * @param v1 vector1
     * @param v2 vector2
     * @return Det Result.
     */
    public static Double Det(Vector v1, Vector v2)
    {
        return v1.x * v2.y - v1.y * v2.x;
    }

    /**
     * 计算从向量V1到V2的顺时针旋转角度
     * @param v1 vector1
     * @param v2 vector2
     * @return the clockwise angle of vector1 to vector2
     */
    public static Double CalcClockWiseAngle(Vector v1, Vector v2)
    {
        var dot = Vector.Dot(v1, v2);
        var det = Vector.Det(v1, v2);
        var theta = Math.atan2(det, dot);
        return theta > 0? theta : 2*Math.PI + theta;
    }

    /**
     * calc the length of the vector
     * @return length value
     */
    public Double length()
    {
        return Math.sqrt(x*x + y*y);
    }
}
